package com.itheima.HomeWork.Exer;

import java.io.File;

public class Fi05 {
    public static int c1 = 0;
    public static int c2 = 0;
    public static int c3 = 0;

    public static void main(String[] args) {
        File f1 = new File("E:\\ttt");
        count(f1);
        System.out.println("txt:" + c1);
        System.out.println("doc:" + c2);
        System.out.println("jpg:" + c3);
    }

    public static void count(File f1) {
        File[] files = f1.listFiles();

        if (files != null) {
            for (File file : files) {
                if (file.isFile() && file.getName().endsWith("txt")) {
                    c1++;

                } else if (file.isFile() && file.getName().endsWith("doc")) {
                    c2++;

                } else if (file.isFile() && file.getName().endsWith("jpg")) {
                    c3++;

                } else {
                    count(file);

                }
            }

        }
    }
}
